package Count;
//反射
 class Student1 {
    private String name="mmm";
    public int age=19;
    public Student1(){
        System.out.println("xxxxxxxxx");
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
public class Student{
     public static void main(String[] args) throws ClassNotFoundException {
//         第一种获取方式用getClass()获取对象
         Student1 s1=new Student1();
         Class s=s1.getClass();
         //2.直接通过类名.class获取class对象
         Class s2=Student1.class;//直接
         //通过Class对象的forName()的静态方法来获取，程序性能更高
         Class s3=null;
         try{
             s3=Class.forName("Count.Student1");//括号里是类的所在包.类名
         }catch (ClassCastException e){
             e.printStackTrace();
         }
         //一个类在jvm中只会有一个Class实例结果为true
         System.out.println(s.equals(s1));//false s是Class类型对象，s1是Student1类型的实例对象
         System.out.println(s.equals(s2));//true
         System.out.println(s.equals(s3));//true
     }
}
